<template>
  <Card title="压电" :loading="loading">
    <div ref="yadianChartRef" :style="{ width, height }"></div>
  </Card>
</template>
<script lang="ts" setup>
  import { Ref, ref, watch } from 'vue';
  import { Card } from 'ant-design-vue';
  import { useECharts } from '@/hooks/web/useECharts';

  const props = defineProps({
    loading: Boolean,
    width: {
      type: String as PropType<string>,
      default: '100%',
    },
    height: {
      type: String as PropType<string>,
      default: '300px',
    },
    yadian: Object
  });

  const yadianChartRef = ref<HTMLDivElement | null>(null);
  const { setOptions } = useECharts(yadianChartRef as Ref<HTMLDivElement>);

  watch(
    () => props.yadian,
    (nVal) => {
      console.log(nVal)
      if (props.loading) {
        return;
      }
      const { date = [], data = [] } = nVal
      setOptions({
        xAxis: {
          type: 'category',
          data: date
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data,
            type: 'line',
            smooth: true
          }
        ]
      });
    },
    { immediate: true },
  );
</script>
